//
//  JCProgressListCell.m
//  JiFengDaRen
//
//  Created by 陈如意 on 2018/5/8.
//  Copyright © 2018年 陈永发. All rights reserved.
//

#import "JCProgressListCell.h"
#import "ProgressModel.h"

@interface JCProgressListCell ()

@property (nonatomic, strong) UIImageView * bankIcon;//银行图标

@property (nonatomic, strong) UILabel * bankName;// 银行名称

@property (nonatomic, strong) UILabel * bankNumber;// 银行账号

@property (nonatomic, strong) UILabel * status;// 还款状态

@property (nonatomic, strong) UILabel * type;// 还款类型

@property (nonatomic, strong) UILabel * amountLabel;// 代扣金额

@property (nonatomic, strong) UILabel * amount;// 代扣金额

@property (nonatomic, strong) UILabel * time;// 代扣金额

@property (nonatomic, strong) UIView * bottomView;//

@property (nonatomic, strong) UILabel * mark;

@end

@implementation JCProgressListCell

+ (instancetype)tableViewCellWithTableView:(UITableView *)tableView{
    static NSString * cellIndentfile = @"JCProgressListCell";
    JCProgressListCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentfile];
    
    if (!cell) {
        cell = [[JCProgressListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentfile];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI{
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    self.bottomView = [UIView new];
    self.bottomView.backgroundColor = [UIColor colorWithHexString:@"#F7F8FB"];
    [self.contentView addSubview:self.bottomView];
    
    self.bankIcon = [UIImageView new];
    self.bankIcon.image = [UIImage imageNamed:@"unionPay"];
    [self.contentView addSubview:self.bankIcon];
   
    self.status = [UILabel new];
    self.status.text = @"还款中";
    self.status.font = KSHSystemFont(14);
    [self.contentView addSubview:self.status];
    
    self.bankName = [UILabel new];
    self.bankName.textColor = [UIColor colorWithHexString:@"#5D5D5D"];
    self.bankName.text = @"农业银行";
    self.bankName.font = KSHSystemFont(20);
    [self.contentView addSubview:self.bankName];
    
    self.type = [UILabel new];
    self.type.text = @"大额还款";
    self.type.font = KSHSystemFont(14);
    [self.contentView addSubview:self.type];
    
    self.bankNumber = [UILabel new];
    self.bankNumber.text = @"333333333";
    self.bankNumber.textColor = [UIColor colorWithHexString:@"#5D5D5D"];
    self.bankNumber.font = KSHSystemFont(16);
    [self.contentView addSubview:self.bankNumber];

    self.amountLabel = [UILabel new];
    self.amountLabel.text = @"代扣金额";
    self.amountLabel.font = KSHSystemFont(16);
    self.amountLabel.textColor = [UIColor colorWithHexString:@"#2C2C2C"];
    [self.contentView addSubview:self.amountLabel];
    
    self.mark = [UILabel new];
    self.mark.text = @"¥";
    self.mark.font = KSHSystemFont(14);
    self.mark.textColor = [UIColor colorWithHexString:@"#EB8A3D"];
    [self.contentView addSubview:self.mark];
    
    self.amount = [UILabel new];
    self.amount.text = @"140";
    self.amount.font = KSHSystemFont(26);
    self.amount.textColor = [UIColor colorWithHexString:@"#EB8A3D"];
    [self.contentView addSubview:self.amount];

    self.time = [UILabel new];
    self.time.textColor = [UIColor colorWithHexString:@"#9A9898"];
    self.time.font = KSHSystemFont(14);
    self.time.text = @"代扣时间";
    [self.contentView addSubview:self.time];
}


- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_offset(__I6Height(15));
    }];
    
    [self.bankIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(__I6Width(20));
        make.top.equalTo(self.contentView).offset(__I6Height(15));
    }];
    
    [self.status mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-__I6Width(20)).priority(500);
        make.centerY.equalTo(self.bankIcon);
    }];
    
    [self.bankName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankIcon.mas_right).offset(__I6Width(12));
        make.centerY.equalTo(self.bankIcon);
        make.right.equalTo(self.status.mas_left).offset(-10).priority(100);
    }];
    
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.status.mas_right);
        make.centerY.equalTo(self.bankNumber);
    }];
    
    [self.bankNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankName.mas_left);
        make.top.equalTo(self.bankName.mas_bottom).offset(__I6Height(8));
    }];

    [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bankNumber.mas_left);
        make.top.equalTo(self.bankNumber.mas_bottom).offset(__I6Height(20));
    }];
    
    [self.mark mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.amountLabel.mas_right).offset(__I6Width(9));
        make.bottom.equalTo(self.amountLabel.mas_bottom);
    }];
    
    [self.amount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mark.mas_right);
        make.bottom.equalTo(self.mark.mas_bottom).offset(3);
    }];
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.amountLabel.mas_left);
        make.top.equalTo(self.amountLabel.mas_bottom).offset(__I6Height(8));
    }];
}
- (void)setProgressModel:(ProgressModel *)progressModel{
    _progressModel = progressModel;

    self.bankName.text = progressModel.bankName;
    self.bankNumber.text = progressModel.cardNo;
    self.time.text = [NSString stringWithFormat:@"代扣时间 %@",progressModel.trade_time];
    self.amount.text = progressModel.transfer_amount;
    self.status.text = [self getStatusText:progressModel.repay_status];
    self.type.text = [self getChannel_type:progressModel.channel_type];
}

- (NSString *)getStatusText:(NSString *)str{
    if ([str isEqualToString:@"Repaying"]) {
        self.status.textColor = [UIColor colorWithHexString:@"#3D9EEB"];
        return @"还款中";
    }else if ([str isEqualToString:@"Success"]){
        self.status.textColor = [UIColor colorWithHexString:@"#C8C8C8"];
        return @"还款成功";
    }else if ([str isEqualToString:@"Fail"]){
        self.status.textColor = [UIColor colorWithHexString:@"#EB3D3D"];
        return @"还款失败";
    }else{
        self.status.textColor = [UIColor colorWithHexString:@"#C8C8C8"];
        return @"已终止还款";
    }
}

- (NSString *)getChannel_type:(NSString *)str{
    if ([str isEqualToString:@"1"]) {
        return @"小额落地商户";
    }else{
        return @"大额还款";
    }
}


@end
